package hao.itheima.controller;


import hao.itheima.entity.Clazz;
import hao.itheima.entity.Result;
import hao.itheima.service.ClazzService;
import hao.itheima.service.impl.ClazzServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j // 使用日志框架
@RestController
public class ClazzController {


    @Autowired
    private ClazzService clazzService;
    /**
     * 查询所有班级信息
     * @return
     */
    @GetMapping("/clazzs/list")
    public Result list() {
       List<Clazz> clazzs = clazzService.list();
        return Result.success(clazzs);
    }


    /**
     * 新增班级信息
     * @param clazz
     * @return
     */
    @PostMapping("/clazzs")
    public Result insert(@RequestBody Clazz clazz) {
       Integer count = clazzService.insert(clazz);
        log.info("影响的行数,{}", count); // 减少字符串的拼接, 性能更加好
        return Result.success();
    }
}
